home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Education
/
World of Education.iso
/
world_j
/
jabr103.zip
/
ALJABR.DOC
< prev
next >
Wrap
Text File
|
1991-04-06
|
32KB
|
679 lines
Al-Jabr V1.03
The Numerically Oriented Mathematics Program.
Copyright (c) 1991 by Uchenna Ogbuji
PART I: INTRODUCTION AND MATHEMATICAL EXPRESSIONS
Al-Jabr is a multi-purpose mathematical program. It can be used as a
sophisticated calculator with multiple-graphing capabilities. I wrote it
with college students in mind and others who would appreciate some
assistance on their mathematical problems but can hardly afford the more
sophisticated symbolic packages.
Al-Jabr uses a command-line interface. You enter commands at the
command prompt (">"), they are executed, and then you are returned to the
prompt. You just enter "quit" at the prompt to exit the program. The screen
is divided into two. The command area occupies the lower 5 lines; this is
where you enter your commands and where Al-Jabr displays its status and
error messages. The upper part of the screen is the viewing area where
graphs are plotted and where other information may be displayed.
Al-Jabr understands mathematical information in the form of
"expressions". Expressions are basically functions that can be evaluated,
graphed, and stored in memory. Expressions consist of numbers and
constants, variables, operators, functions and series:
Numbers: Real numbers in decimal or scientific notation.You can enter
numbers to any number of decimal places but they will be
truncated to about 13 significant digits in the computer.
Numbers are expressed in scientific notation using the
standard notation for floating point numbers: there is a
mantissa which contains the significant digits followed by
the letter "e" or "E" which means "times ten to the power"
and then the exponent, which is the power to which ten is
raised. The exponent can be preceded by a sign ("+" or "-").
There must be no spaces within a number whatsoever, not even
between the mantissa and the exponent.
Examples:
-10
30.673197508
235.37e24 (235.37 times ten to the power 24)
9.674E-46 (9.674 times ten to the power minus 46)
Constants: Common constants that have been pre-defined by Al-Jabr. They
are all represented by a colon followed by a letter. There
are only three currently pre-defined constants. There are :p
or pi (3.141592654), :e which is the mathematical constant e
(2.718281828), and :c which is the degrees-to-radians
conversion factor (:p/180 = 0.017453293). I realize that the
colons are cumbersome but they are neccesary to
differentiate constants from variables.
variables: Variables are represented by single letters. Thus you can
have up to 26 of them. They can contain any real number.
Upper-case letters are considered the same as lowercase
letters.
operators: Al-Jabr supports all of the common arithmetical operators:
+ addition;
- subtraction ;
* multiplication;
/ division;
^ exponentiation (a^b returns a to the power b);
mod modular operator (a mod b divides a by b and
returns the remainder);
\ or div integer division ( a\b [or a div b] returns the
largest integer that is not greater than a/b);
- a unary minus sign (as in -51) simply returns the
negative of the value to the right.
functions Most of the common mathematical functions are supported as
well:
sin x *returns the sine of x;
cos x *returns the cosine of x;
tan x *returns the tangent of x;
sinh x returns the hyperbolic sine of x;
cosh x returns the hyperbolic cosine of x;
tanh x returns the hyperbolic tangent of x;
sqrt x returns the POSITIVE square root of x;
log x returns the logarithm of x to the base 10;
ln x returns the natural logarithm of x (the logarithm
to the base :e);
exp x returns :e to the power x;
abs x returns the absolute value of x;
asin x *returns the inverse sine or arcsine of x;
acos x *returns the inverse cosine or arccosine of x;
atan x *returns the inverse tangent or arctangent of x;
x! returns the factorial of x (eg. 5!=5*4*3*2*1,
3!=3*2*1. Note: 1!=1, 0!=1.)
*Please note that all trigonometric expressions are computed
in terms of radians, not degrees.
series: You might want to skip the discussion of sequence summation
and products until you have read the rest of this manual or
until you have used the tutorial. The following explanation
is perhaps simpler for those with some programming
experience in any computer language.
Al jabr can quickly compute sums and products of sequences.
sums of sequences are expressed as follows:
[n = start, stop, step, expression]
while products of sequences are expressed as follows:
{n = start, stop, step, expression}
where n can be replaced by any variable, "start", "stop",
"step" (which is optional), and "expression" can be replaced
by any expression. The operation of the sequence functions
can best be explained with a few examples:
[q=3,9,2,q^2] Al-Jabr makes the following series of
calculations:
sum = 0.0
q = 3.0
loop: if q is greater than 9 then goto end
q = q + 2
sum = sum + q^2
goto loop
end: return sum
{b=5,10,1,b} Al-Jabr does the following:
product = 1.0
b = 5.0
loop: if b is greater than 10 then goto end
b = b + 1
product = product * b
goto loop
end: return product
[n=1,100,5-4,sin n] Al-Jabr does the following:
sum = 0.0
n = 1.0
loop: if n is greater than 100 then goto end
n = n + (5-4)
sum = sum + sin n
goto loop
end: return sum
{x=-20,20,2,1} product = 1.0
x = -20
loop: if x is greater than 20 then goto end
x = x + 2
product = product * 1
goto loop
end: return product
You may have observed that the last example will simply return
1.0! If you still do not understand the summation and product of
sequence functions, perhaps the examples in the tutorial will
clarify them. Note that as a short cut if you don't specify a
step (if you just use a comma), Al-Jabr assumes a step value of
1, i.e. [k=1,3,,k] is evaluated as [k=1,3,1,k], and
{i=24,100,,sqrt i} is evaluated as {i=24,100,1,sqrt i}.
Expressions are composed of any mathematical combination of the above, hence sample expressions are:
3 * sin x
-57.2
2*x^2 + x -1
exp (f*ln f)
cos (20 * :c) Note: this returns the cosine of 20 degrees, not
radians (when multiplied to an angular value in
degrees :c converts it into a value in radians)
[a=1,10,1,a] Note: this returns the sum of all integers between
1 and 10
sqrt ( abs (sin (:p * m)))
x^2 + x*y + y^2
log (n!)
{y=3,33,3,y/10}
57 * 3e-67
cosh 3.33
atan (-b/a)
3 + [n=1,4,1,n^2] / 2 - (1 / :e)
In mathematics one has to have a certain order in which calculations
are done. For instance the expression 5-3*4 could have two answers: if we
did the subtraction first we would get 8, if we did the multiplication
first we would get -7. To avoid confusion there is a generally accepted
order of evaluation of operators which Al-Jabr follows. This leads to what
is known as operator precedence which is a table of the order in which
operators are evaluated. Note that normal precedence can be overridden with
parentheses because expresions in parentheses are always evaluated first.
For instance, multiplication has a higher precedence than subtraction and
thus Al-Jabr would normally return -7 for 5-3*4, but if we write instead
(5-3)*4 then the expression in parenthesis (the subtraction) would be
evaluated first and Al-Jabr would return 8. Here is a table of operator
precedence in Al-Jabr. The highest items are evaluated first and the lowest
operators are evaluated last.
OPERATOR PRECEDENCE IN AL-JABR
1: (),[],{} <i.e all bracketed expressions and summation or product of sequences are evaluated first of all>
2: ! <factorial>
3: - <unary minus>
4: sin,cos,tan,tanh,abs,tanh,sinh,cosh,asin,acos,atan,sqrt,log,ln,exp
5: ^
6: *,/,\,div,mod
7: +,- <binary plus and minus>
Whithin any given precedence level the operators are evaluated from left to
right EXCEPT on level 4 where they are evaluated from right to left. For
instance, 16/4*2 will return 8 because since the / and the * are on the
same level, they are considered from left to right and the / is evaluated
first. However sin cos x would first of all evaluate cos x and then find
the sine of that.
Here are more examples: sin 2*x will first evaluate the sine of 2 and
then multiply this by x since sin has higher precedence than *, but sin
(2*x) would first of all find 2*x and then find the sine of the result.
However, sin -x would first of all negate x and then find the sine of the
result since the unary minus has higher precedence than sin. There is one
exception to the above precedence tables. I had to make this exception to
conform to regular math usage: -sin x first evaluates the sine of x and
then negates it although the unary minus has higher precedence than the sin
function. The same goes for -log x, -atan x, -sqrt x, -cosh x etc.. You can
experiment a little to help understand this concept of precedence.
Al-Jabr has a set of commands for manipulating expressions and for
other uses. These commands are the subject of the next section.
PART II: THE COMMMAND SET
ASSIGNMENT:
The simplest command in Al-Jabr is the assignment. You can assign any
valid value to any variable in the following way:
variable=expression
where "variable" can be any variable from a to z, and "expression" can be
any valid expression. When you make an assignment the expression is first
evaluated and Al-Jabr tells you the value, then the variable is updated in
memory so that any time you use it in any future expression it will return
the value you have assigned it. For example if you enter
z = -5 * abs (-20)
Al-Jabr evaluates 5*abs(-20) and reports that the answer is -100.00 and
then updates z so that if you were to type "c = z", c would be assigned the
value of z which is -100.
Please note that when you first run Al-Jabr, all variables are set to
zero, however you can use them in any expression without first assigning
them a value. They will just return 0.
STORE:
The store command will be easier to understand if you have gone
through the tutorial. You can store up to 9 expressions in memory at a
time. The first expression you store is labelled #1, the second, #2 etc. up
to #9. You can use any of these stored expressions anywhere in other
expressions, eg. if sin x has been stored as #3, then
y=cos x + #3
is the same as
y=cos x + sin x
Stored expressions can be used to avoid typing the same expression over and
over again.
Expressions are stored in memory with the "store" command. You can use
it in two ways. one way is to enter:
store variable = expression
this does exactly the same thing as a regular assignment but it also stores
"expression" in memory.
Al-Jabr also remembers the last expression you used in any command,
whether assignment or plotting. If you just enter "store" and nothing else
at the command prompt Al-Jabr will store the last expression you used in
any command in memory. For example if you enter
v = 4*acos f
Al_Jabr will make the normal assignment. If you then enter "store", Al-Jabr
remembers that the last expression you worked with was "4*acos f and stores
it in memory. whichever method you use Al-Jabr will inform you of the
number of your new expression. If you forget it you can use the "show"
command which is discussed next.
SHOW:
You can display the values of variables and all stored expressions
expressions using the show command. You can just enter "show" followed by a
variable or stored expression name and Al-Jabr will display the contents of
that variable or expression. Here are some examples:
show g
will display the contents of the variable a.
show #5
will show the stored expression #5. You can also show all the variables or
all the stored expressions at once with the commands: "show all" and show
#all" respectively. When you execute either of these commands a window
opens in the viewing area displaying all the stored expressions and
variables. Both of these windows can be displayed at the same time. While
these windows are open, if you change the value of a variable or add a new
expression, the windows are updated automatically.
PRINT:
The print command sends a list of all stored expressions and variables
to your printer, if you have one. You just enter "print" at the prompt and
all the information is printed. Simplicity!
PLOT:
Al Jabr has very good graphing, scaling, clipping and error-trapping
features. This is all accomplished by the plot command. The syntax of the
plot command may take some practice. Again perhaps it will be easier to
complete the tutorial before reading this full documentation. The general
syntax to plot a graph in the viewing area is as follows:
plot x;expression;xmin,xmax[,ymin,ymax]
where "x" can be replaced by any variable, "expression" can be replaced by
any expression. xmin, xmax, ymin, and ymax refer to the minimum and maximum
values for the horizontal and vertical axes respectively. ymin and ymax are
optional; if they are not specified, Al-Jabr will automatically scale the
vertical axis so that the whole graph can be shown (except, of course,
unrepresentable regions like singular points and imaginary numbers).
Perhaps some examples will elucidate:
plot k; 3*k + 1 ;-5,5,-10,10
draws the graph of the line 3k+1, letting k vary from -5 to 5 on the
horizontal axis and clipping off all values of 3k+1 that are greater than
10 or less than -10. Now if you were to enter instead just
plot k; 3*k + 1;-5,5
Al-Jabr would first of all calculate the maximum and minimum values 3k + 1
can take between k=-5 and k=5. It will then scale the vertical axis so that
the entire line can be shown. This scaling process takes a little time so
if you do know the extrema of your function whithin your horizontal axis
range, or if you are only interested in a certain region of the graph then
you might want to specify ymax and ymin.
Please note that Al-Jabr cannot perform automatic scaling for graphs
that have a singularity (e.g. ln (x) at x=0) or a domain error (eg. acos
(x) at x<-1 or x>1). For example, if you were to enter
plot c; ln (3-c) ;0,10
then Al-Jabr would attempt to scale your function between c=0 and c=10, but
it would find a singularity at c=3 and terminate with an error. You can
still view the function ln (3-c) between 0 and 10 but you would have to
specify the vertical range, for example:
plot c; ln (3-c) ;0,10,0,2
would show the whole graph except for portions where ln (3-c) > 2 or ln (3-
c) < 0, and the portions where c >= 0 (because ln 0 is a singularity and
negative logarithms do not exist). Here are some other sample graphs you
might want to try. There are more in the tutorial.
plot a; 1/a ;-5,5,-5,5 (a hyperbola)
plot x; 3*x^2 - 4*x +2; -10,10 (a cubic polynomial)
plot r; 2*sin x + cos (2*x);-5,5 (a "humped" cosine wave)
plot d; 1/tan x ;-3.14,3.14,-10,10 (the cotangent curve)
And for the engineers among you, here is the fourier series approximation
(taken to 3 terms) to an even square wave:
plot t; 4/:p * [n=1,5,2,(1/n)*sin (n*:p*t)]; -8,8,-4,4
Note: if you have a graph in the viewing area, you can still use the
"show" command to display all variables and stored expressions in the
viewing area without losing the graph that is currently there. The list of
variables and stored expressions will block out parts of the graph, but you
can always show the graph again by entering:
show plot
this will redraw the last graph that was on the screen.
OVER:
With Al-Jabr you can show more than one graph at once. To plot a graph
over one that is currently in the viewing area, use the "over" command. The
syntax of the "over" command is similar to that of "plot" except you don't
specify the ranges of the horizontal or vertical axes. The new graph will
be plotted on exactly the same grid as the older one. For example:
over x; sin -x + cos x
will plot the curve of sin (-x) + cos x over the previous curve with the
same axis scalings. You can use the "over" command again and again. There
is no limit to the number of curves you can display at any time. When you
use the "over" command you are prompted for the color you wish the curve to
be drawn in. Al-Jabr allows graphs in four different colors, white, grey,
yellow, and cyan, to enhance clarity.
Note: If you already have a graph plotted in the viewing area, and you
issue another "plot" command, the first graph will be erased and your new
one will be displayed. "Over" is the only way to show more than one graph
simultaneously.
CFIT:
You can fit a polynomial curve to a set of data with the "cfit"
command. Al-Jabr reads the data from a data file which you specify with the
"cfit" command. The general syntax is:
cfit [path\]filename.ext
where "path\" is an optional dos path (drive and/or subdirectory) and
"filename.ext" can be replaced by any valid DOS filename. For example,
cfit a:infile.dat
will read the data out of the file "infile.dat" in the "a" drive. You can
use a text editor or a word-processor that can save documents in plain
ASCII format to make the data file. The format of the data file is very
simple. It should consist of rows of data separated by carriage returns
(ASCII character 13). Each row contains an x-value a corresponding y-value
and then an optional weight. The weighting factor is an optional
nonnegative number you can assign to each data pair to determine how
important that data pair will be in determining the resulting polynomial.
For instance, if you used a more reliable method to obtain some data pairs
you might assign them a higher weighting value. A weight of 1 gives the
normal importance to a data pair, a weight less than 1 assigns a lower
importance, and a weight of more than 1 assigns a greater importance. Note
that there should be no spaces between the last number on a line (or row)
and the carriage return. Some sample data file contents follow. <cr> means
"carriage return".
3.4 6.2 1<cr>
2.007 4.8 3<cr>
4.34 9.134 1<cr>
5.9 10.29 0.7<cr>
7.31 11.5 0.6<cr>
note that
0.09 34.6 1<cr>
0.10 30.5 1<cr>
0.11 25.89 1<cr>
0.12 23.0 1<cr>
0.13 19.76 1<cr>
0.14 15.09 1<cr>
is exactly the same as
0.09 34.6<cr>
0.10 30.5<cr>
0.11 25.89<cr>
0.12 23.0<cr>
0.13 19.76<cr>
0.14 15.09<cr>
because when a weight is not specified, the weighting factor is assumed to
be 1 i.e. normal weighting.
When all the data pairs have been read in, Al-Jabr finds a polynomial
of best STATISTICAL fit. This means that the polynomial might not touch
every data point on the curve, because it is assumed that experimental
errors and the like may be involved, but the curve will represent the
general trend of the data in a way that preserves the highest information
content. This makes your graph more reliable for extrapolating or
interpolating other values from your curve. When Al-Jabr computes the
fitted polynomial it is plotted in the viewing area and all the input pairs
of data are shown as small circles. The curve-fitting function is an
experimental statistical addition to Al-Jabr to try out further statistical
abilities that may be added to later versions. I would appreciate some
feedback as to how useful users find this polynomial curve-fitting facility
and which other statistical functions would be most desirable in a new
version of Al-Jabr.
CAPTURE:
It is all very well to have an impressive graph or set of graphs on
your screen but I suspect an alterable, hard copy would prove even more
useful for most. Al-Jabr can capture any graph to a graphics file in the
popular PCX format. The PCX format is so popular that most paint programs
and graphics viewing programs support it. Many advanced word-processors and
desk-top publishing programs can import .PCX directly into documents so you
can include Al-Jabr graphs in papers and the like. You could alter the
graphs with paint programs like Zsoft's PC Paintbrush (TM) in order to say,
place labels or the like on the graphs.
To capture a graph to a file you use the "capture" command, specifying
the file name. The general syntax is:
capture [path\]filename.ext
Where path is any valid dos path. The extension will usually be .pcx, of
course, because that is the standard extension for PCX format files. So if
you were to enter
capture c:\pbrush\graph1.pcx
Al-Jabr would store the graphs currently being shown in the viewing area to
the filename "graph1.pcx" in the subdirectory "\pbrush" of the "c" drive.
The capturing process may take about a minute.
Note: any grphical output can be captured, including the output from
the "cfit" command, and multiple graphs plotted using "over".
PART III ERROR MESSAGES
When Al-Jabr meets a difficulty it cannot handle, or if it can't
understand your command, an error message will be issued and you'll
generally have to correct the problem and re-enter the command. Here are
Al-Jabr's error messages and explanations of the situations that might have
caused them.
Error 00: Unrecognized command.
This means Al-Jabr does not understand your command at all. The only
commands, apart from variable assignment, recognized by Al-Jabr at this
time are "store", "show", "print", "plot", "over", "cfit", "capture", and
"quit".
Error 01: Syntax error in command.
Al-Jabr knows your command but you didn't follow the required syntax.
See the manual section on commands (part II) for descriptions of the
correct syntax.
Error 02: Number too large or small to process.
Al-Jabr can only handle numbers between about -1.7e+308 and 1.7e+308
(which is quite an enormous range actually) and if it comes across any
number outside this range in any calculation the above error will occur. If
this error occurs you must take steps to reduce the magnitude of initial,
intermediate or final values in the calculation.
Error 03: The argument to FUNCTION is out of its domain.
Where FUNCTION is replaced by the mathematical function that caused
the error. This means that the argument to the function is out of the
domain in which the function can be evaluated. For example, a negative
argument to the logarithm or square root functions will cause such an
error.
Error 04: The argument to FUNCTION is too large.
Some functions, notably sin, cos, sinh and cosh, are difficult to
evaluate accurately when their arguments are too large. If Al-Jabr cannot
accurately evaluate a function for this reason the above error will be
generated.
Error 05: A number approaching +/- infinity was encountered.
This is similar to error 2 and occurs when Al-Jabr encounters a
singularity.
Error 06: Division by Zero.
A division by zero has been attempted, resulting in a value Al-Jabr
cannot handle.
Error 07: Syntax error in expression.
There is a logical error in your mathematical expression. Quite a few
situations can cause this error. The most common are forgetting to close a
bracket and missing operators. Please check the expression you last used
and make sure it is valid under the rules of Al-Jabr and mathematics.
Error 09: Syntax error in sequence summation of product.
Check that you included all the required parameters and commas, and
closed the bracket of your sequence summation or product. The correct
syntax for sequence summation and product is explained in part I of the
manual.
Error 10: Undefined user expression.
If you are trying to specify a stored user expression with the #X
notation, X must be a digit between 1 and 9 and there must be no space
between the "#" and the digit. In any other case the above error will be
generated.
Error 11: Invalid horizontal axis range.
This occurs in the plot function when either you specify the minimum
and maximum ranges for the horizontal axis to be the same, or if you make
the minimum larger than the maximum.
Error 12: Invalid vertical axis range.
This occurs in the plot function when either you specify the minimum
and maximum ranges for the vertical axis to be the same, or if you make the
minimum larger than the maximum.
Error 13: Invalid statistics file format.
Al-Jabr cannot correctly obtain data from the file you specified with
the "cfit" command. See the "cfit" command description for the correct
format of the data file.
Error 14: Unable to create the file FILENAME.
Most probably FILENAME (which is replaced by whatever filename Al-Jabr
is having trouble with) is not a valid DOS filename.
Error 15: Unable to open data file FILENAME.
The FILENAME you specified cannot be found on the path you specified
(or on the current path if you didn't specify a path) or perhaps it is not
a valid DOS filename.
Error 92, Error 93, Error 99.
These errors are not ever meant to occur, and if they do, they might
reflect serious bugs in Al-Jabr. For this reason if you encounter any of
these errors please contact me immediately and tell me which one you
encountered and the circumstances under which you encountered it. My
Prodigy ID number is KTXR86A; You can send me mail at the following
address:
Uchenna Ogbuji
c/o Dr L. U. Thomas-Ogbuji
20373 Lorrain Road #F-7
Fairview Park OH 44126
or you can leave e-mail for me (Uche G. Ogbuji) on Ed Gelb's Database BBS
[300,1200 baud, 8/1/N] #(201)-694-7425.